$(document).ready(function() {
    bindEvent();
    getDataEvent();
});


function bindEvent(){
    var ipt_zf = $('#ipt_zf'),
        btn = $('#sp_btn'),
        msg = '亲！把绽放心语码这里！一同见证绽放哟~~限50字以内',
        maxCount = 50;
    ipt_zf.focus(function(){
        var me = $(this);
        if(ipt_zf.val()===msg){
            me.val('');
            me.addClass('notxt');
        }
    });
    /*ipt_zf.bind('input',function(){
        var me = $(this);
    }.bind(this));*/

    ipt_zf.blur(function(){
        var me = $(this);
        if(me.val() == ''){
            me.val(msg);
            me.removeClass('notxt');
        }
    });
/*
    ipt_zf.bind('focus',function(){
        var me = $(this);
        if(ipt_zf.val()===msg){
            me.val('');
            me.addClass('notxt');
        }
    });
    ipt_zf.bind('input',function(){
        var me = $(this);
    }.bind(this));

    ipt_zf.bind('blur',function(){
        var me = $(this);
        if(me.val() == ''){
            me.val(msg);
            me.removeClass('notxt');
        }
    });
*/
    btn.bind('click',function(){
        addEvent();
        setTimeout(function () {
            window.location.href = home_url;
        }, 5000);
    });
}


//添加祝福
function addEvent(){
    var con = $('#layer_con'),
        name = $('#layer_name'),
        ipt_zf = $('#ipt_zf').val();

    jQuery.ajax({
        url:ajax_url,
        data:{
            'type':'add',
            'content':ipt_zf
        },
        type:'get',
        success:function (data) {
            var datas = eval('(' + data + ')');
            if(datas.errcode === 1){
                $('#layer').show();
                con.html(ipt_zf);
                name.html(user_name);
                $('#def_id').addClass('on');
                $('#def_id').attr('uid',user_id);
                $('#my_content').val($('#ipt_zf').val());
                //$('#layer_con1').html($('#ipt_zf').val());
               /* $('#sp_btn').attr('disabled','disabled');*/
            }
        }
    });
}

function getDataEvent(){
    $('#panel_p2d span').bind('mouseover',function(){
        var me = $(this),
            Top = me.attr('top'),
            Left = me.attr('left'),
            uid = me.attr('uid'),
            layer = $('#layer');

        if(uid!=0){
            if(uid===user_id){
                $('#def_layer').show();
                /*if(!is_edit){
                    $('#layer_con1').html($('#ipt_zf').val());
                    $('#layer').show();
                    $('#def_layer').hide();
                }*/
                $('#layer').hide();
                $('#layer_name1').html('--' + user_name);
                $('#layer_con1').html($('#ipt_zf').val());
                layer.css("left",530+'px');
                layer.css("top", 230+'px');
            }else{
                layer.css("left",Left+'px');
                layer.css("top", Top+'px');
                $('#layer').show();
                $('#def_layer').hide();
            }
        }
        /*if(uid===user_id){
            $('#def_layer').show();console.log('adsdfj',$('#ipt_zf').val());
            if(!is_edit){
                $('#layer_con1').html($('#ipt_zf').val());
            }
            $('#layer_name1').html('--' + user_name);
            $('#layer').hide();
            layer.css("left",530+'px');
            layer.css("top", 230+'px');
        }else{
            if(uid!=0){
                layer.css("left",Left+'px');
                layer.css("top", Top+'px');
                $('#layer').show();
                $('#def_layer').hide();
            }
        }*/


    });
}